home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pnl004.zip / PROTIMER.ASM < prev   
Assembly Source File  |  1990-02-15  |  2KB  |  69 lines

  1. ; assembler subroutine to read system's timer with microsecond-resolution
  2. ; PROTIMER.ASM                            (c) Jan-Erik Rosinowski 1989
  3. ;
  4. ; Publics : PROCEDURE INITTIMER         : prepares timer for its duty
  5. ;           PROCEDURE RESTORETIMER      : restore timer's original state
  6. ;           FUNCTION  READTIMER:LONGINT : the kernel-procedure
  7.  
  8. code    segment byte public
  9.         assume     cs:code,ds:code
  10.         public     readtimer,inittimer,restoretimer
  11.  
  12. counter =          0
  13. corr    =          5
  14. tport   =          40h
  15. tctrl   =          tport+3
  16. ictrl   =          20h
  17.  
  18. inittimer proc
  19.         mov        al,34h
  20.         jmp        short skip1
  21. inittimer endp
  22.  
  23. restoretimer proc
  24.         mov        al,36h
  25. skip1:  out        tctrl,al
  26.         mov        cx,2
  27. itl:    mov        al,0
  28.         out        tport,al
  29.         loop       itl
  30.         ret
  31. restoretimer endp
  32.  
  33. readtimer proc
  34.         push       bp
  35.         mov        bp,sp
  36.         push       ds                  ;we'll need dosseg
  37.         cli                            ;disable all interrupts
  38.         mov        al,00001010b        ;set ocw 3 to read interrupt-request..
  39.         out        ictrl,al            ; ..register
  40.         in         al,ictrl            ;read it
  41.         mov        cl,al
  42.         mov        al,counter shl 6    ;function latch timer
  43.         out        tctrl,al            ;latch timer
  44.         in         al,tport            ;read timer low
  45.         mov        bl,al               ;into bl
  46.         in         al,tport            ;read timer high
  47.         mov        bh,al               ;into bh, bx=clicks mod 64k
  48.         mov        ax,40h              ;switch to dosseg
  49.         mov        ds,ax
  50.         mov        dx,word ptr ds:[6ch];get clicks div 64k
  51.         sti                            ;enable all interrupts
  52.         not        bx                  ;we need ascending count
  53.         test       cl,00000001b        ;timer requested int ?
  54.         jz         exit                ;no
  55.         cmp        bx,corr             ;interrupt while reading
  56.         ja         exit                ;probably not
  57.         inc        dx                  ;timer int disabled via cli
  58. exit:   pop        ds                  ;back to original ds
  59.         mov        ax,bx
  60.         mov        [bp-4],ax           ;lsw
  61.         mov        [bp-2],dx           ;msw
  62.         mov        sp,bp
  63.         pop        bp
  64.         ret
  65. readtimer endp
  66. code    ends
  67.  
  68.         end
  69.